import { injectable } from "../../inject";

@injectable('TimeOffSetManager')
export class TimeOffSetManager {

    private runTick: number = 0;
    private startTime: number = 0;

    update(dt) {
        this.runTick += dt;
    }

    setBeginTime(t: number) {
        this.runTick = 0;
        this.startTime = t;
    }

    getTime(): number {
        return Math.floor(this.startTime + this.runTick);
    }

    getServerUTCSecond(): number {
        return this.getTime();
    }

    getServerUTCDate(): Date {
        let svrUtcSecond = this.getServerUTCSecond();
        let retDate = new Date();
        retDate.setTime(svrUtcSecond * 1000);

        return retDate;
    }

    getWeekDay(): number {
        return this.getServerUTCDate().getDay();
    }

    getHours(): number {
        return this.getServerUTCDate().getHours();
    }

    getMinutes(): number {
        return this.getServerUTCDate().getMinutes();
    }

    getSeconds(): number {
        return this.getServerUTCDate().getSeconds();
    }
}